package com.data.modules.smzh.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.data.common.constant.enums.ProductEnum;
import com.data.common.util.KamliClientUtil;
import com.data.modules.sm.entity.SmProject;
import com.data.modules.sm.service.ISmProjectService;
import com.data.modules.smzh.entity.*;
import com.data.modules.smzh.mapper.SmEmergMsgMapper;
import com.data.modules.smzh.service.IBuildingService;
import com.data.modules.smzh.service.IDevicebuildService;
import com.data.modules.smzh.service.ISmDeviceVersionService;
import com.data.modules.smzh.service.ISmEmergMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.*;

/**
 * @Description: 应急广播
 * @Author: data-boot
 * @Date:   2023-08-18
 * @Version: V1.0
 */
@Service
public class SmEmergMsgServiceImpl extends ServiceImpl<SmEmergMsgMapper, SmEmergMsg> implements ISmEmergMsgService {

    @Autowired
    private ISmProjectService projectService;

    @Autowired
    private IBuildingService buildingService;

    @Autowired
    private IDevicebuildService devicebuildService;

    @Autowired
    private ISmDeviceVersionService versionService;

    @Override
    public void pushMsg(String ids, String model, String projectNo) {

        SmEmergMsg msg = this.getById(ids);

        List mapList = new ArrayList();
        Map map = new HashMap<>();
        map.put("title",msg.getTitle());
        map.put("content",msg.getContent());
        mapList.add(map);
        String comd = "emergMsg";

        //查询版本通知接口
        List<SmDeviceVersion> list = versionService.lambdaQuery().eq(SmDeviceVersion::getModel,ProductEnum.SMW_GDXW.getCode()).list();
        list.stream().forEach(x->{

            KamliClientUtil.doPostpushMsgUr(x.getSn(),comd,mapList);
        });

        SmEmergMsg smPushMsg = new SmEmergMsg();
        smPushMsg.setId(ids);
        smPushMsg.setResult(1);
        smPushMsg.setUpdateTime(new Date());
        this.baseMapper.updateById(smPushMsg);

    }
}
